﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Hosting;

namespace EPiBoost.Core.Helpers.Resources
{
	internal class ResourcePathProvider : VirtualPathProvider
	{
		private readonly string _virtualPath;
		private readonly string _resourceName;
		private readonly bool _physicalResource;
		public ResourcePathProvider(string virtualPath, string resourceName, bool physicalResource)
		{
			_virtualPath = virtualPath;
			_resourceName = resourceName;
			_physicalResource = physicalResource;
		}
		public override bool FileExists(string virtualPath)
		{
			return string.Compare(virtualPath, _virtualPath, true) == 0 || Previous.FileExists(virtualPath);
		}
		public override VirtualFile GetFile(string virtualPath)
		{
			if (string.Compare(virtualPath, _virtualPath, true) != 0)
				return Previous.GetFile(virtualPath);

			return new ResourceVirtualFile(_virtualPath, _resourceName, _physicalResource);
		}
	}
}
